package com.example.healkep.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.healkep.R;

import java.util.List;

public class diseaseItemAdapter extends RecyclerView.Adapter<diseaseItemAdapter.myViewHolder> {
    private View.OnClickListener listener;
    private View.OnLongClickListener longListener;
    private Context context;
    private List<String> diseases;
    public diseaseItemAdapter(Context context,View.OnClickListener listener,View.OnLongClickListener longListener,List<String> diseases){
        this.context = context;
        this.listener = listener;
        this.longListener = longListener;
        this.diseases = diseases;
    }
    public void update(List<String> newData){
        diseases = newData;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.disease_item, parent,false);
        return new myViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull myViewHolder holder, int position) {
        if(listener!=null)
            holder.textView.setOnClickListener(listener);
        if(longListener!=null)
            holder.textView.setOnLongClickListener(longListener);
        holder.textView.setText(diseases.get(position));
    }

    @Override
    public int getItemCount() {
        return diseases.size();
    }

    static class myViewHolder extends RecyclerView.ViewHolder{
        private TextView textView;
        public myViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_disease);
        }
    }
}
